package com.song.shop.thread;

import java.util.concurrent.*;

/**
 * @author Song Yinghui
 * @date 2019/2/21
 * @Version 1.0
 */
public class ThreadTest {

    private static int ctn = 0;
    public static void main(String[] args) {
        ThreadTest test = new ThreadTest();
        test.ctn ++;

        ThreadTest test1 = new ThreadTest();
        test1.ctn ++;

        System.out.println(ThreadTest.ctn);


        //定时任务型
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        Runnable task = () -> System.out.println("定时任务");
        //executorService.scheduleAtFixedRate(task,5,3, TimeUnit.SECONDS);


        //多任务型
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
                1, 1, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<>(1000),Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());

        for (int i =0 ;i < 2000; i++){
            poolExecutor.execute(()->{
                try {
                    TimeUnit.MICROSECONDS.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("ctn:---"+ctn);
                ctn++;
            });
        }
    }

}
